<template>
    <div>
        <!--面包屑导航区域-->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home_com' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>HR审核</el-breadcrumb-item>
        </el-breadcrumb>
        <!--卡片视图区域-->
        <el-card>
            <!--搜索区域-->
            <el-row :gutter="20">
                <el-col :span="9">
                    <el-input placeholder="Please input" v-model="queryInfo.query" clearable @clear="getHR_comList">
                        <template #append>
                            <el-button type="primary" @click="getHR_comList">
                                <el-icon style="vertical-align: middle;">
                                    <search />
                                </el-icon>
                                <span style="vertical-align: middle;"> Search </span>
                            </el-button>
                        </template>
                    </el-input>
                </el-col>
                <el-col :span="4"></el-col>
            </el-row>
            <!--HR列表区域-->
            <el-table :data="HRlist" :border="true" :stripe="true">
                <el-table-column prop="id" label="HR编号"></el-table-column>
                <el-table-column prop="name" label="HR姓名"></el-table-column>
                <el-table-column prop="company" label="所属公司"></el-table-column>
                <el-table-column prop="status" label="审核状态"></el-table-column>
                <el-table-column label="操作">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.status" @change="check(scope.row)" />
                    </template>
                </el-table-column>
            </el-table>
            <!--分页区域-->
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="queryInfo.pagenum" :page-sizes="[5, 10, 15, 20]" :page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </el-card>
    </div>
</template>

<script>
export default {
    data() {
        return {
            queryInfo: {
                query: '',
                pagenum: 1,
                pagesize: 10
            },
            HRlist: [
               
            ],
            total: 2
        }
    },
    created() {
        this.getHR_comList();
    },
    methods: {
        async getHR_comList() {
            const json = {
                compID: window.sessionStorage.getItem('token'),
                query: this.queryInfo.query,
                pagenum: this.queryInfo.pagenum,
                pagesize: this.queryInfo.pagesize
            };
            const { data: res } = await this.$http.post('getAllHRByCompID', json)
            if (res.error_code !== 0) {
                return this.$message.error('获取岗位信息失败！')
            }
            console.log(res);
            this.HRlist = []
            this.total = res.data.pageTotal;
            for(var i = 0; i < this.total; i++) {
                this.HRlist.push({
                    id: res.data.list.hrList[i].hrID,
                    name: res.data.list.hrList[i].name,
                    company: res.data.list.hrList[i].company,
                    status: res.data.list.hrList[i].flag == 1 ? true: false
                });
            }
        },
        //监听pagesize 改变的事件
        handleSizeChange(newSize) {
            this.queryInfo.pagesize = newSize
            this.getHR_comList();
        },
        //监听页码值改变的事件
        handleCurrentChange(newPage) {
            this.queryInfo.pagenum = newPage
            this.getHR_comList();
        },
        //修改审核状态
        async check(HRinfo) {
            const status = HRinfo.status;
            const json0 = {
                hrID: HRinfo.id,
                status: 1
            };
            const json1 = {
                hrID: HRinfo.id,
                status: 0
            };
            const json = status ? json0: json1;
            console.log(json);
            const { data: res } = await this.$http.post('accessHR', json)
            console.log(res);
            if (res.result === "false") {
                return this.$message.error('修改审核状态失败！')
            }
            this.$message.success('修改审核状态成功！')
            //重新获取HR数据
            this.getHR_comList()
        }
    }
}
</script>

<style lang="less" scoped>

</style>